/**
 * Created by hejg on 2018/5/25.
 */
import {observable, computed, action} from 'mobx';
import Style from '../../../components/Style';

export default class ProgressPartStore {
    @observable
    selectOrganize = 0;//默认选中机构的第1个下标
    @observable
    organizeOptions = [];//可供选中的机构列表
    @observable
    selectPeriod = 0;//默认选中账期的第1个下标
    @observable
    periodOptions = [];//可供选择的账期列表
    @observable
    screenData = [];//当前页面的核心数据
    @observable
    indicatorVisible = true;//是否启用加载框
    @observable
    indicatorMessage = '';//显示在加载框的文字信息
    @observable
    params = {opTime: '', orgId: 0};//页面的查询条件
    @observable
    selectExpand = -1;//默认情况下均不展开数据
    @observable
    expandData = {};//展开的指标进度详情数据

    @computed
    get effectiveScreenData() {
        return this.indicatorVisible || (this.screenData && this.screenData.length > 0);
    }

    @action
    setSelectOrganize(index) {//设置选中机构的下标
        this.selectOrganize = index;
    }

    @action
    setSelectPeriod(index) {//设置选中账期的下标
        this.selectPeriod = index;
    }

    @action
    setOrganizeOptions = (items) => {
        let organizes = new Array();
        for (let i = 0; i < items.length; i++) {
            organizes.push({label: items[i].ORG_NAME, value: items[i].ORG_CODE});
        }
        this.organizeOptions = organizes;
    }

    @action
    setPeriodOptions = (items) => {//设置账期列表数据集
        let periods = new Array();
        for (let i = 0; i < items.length; i++) {
            periods.push({label: items[i], value: items[i]});
        }
        this.periodOptions = periods;
    }

    @action
    setScreenData = (data) => {//设置屏幕核心数据及展开数据
        this.screenData = data;
    }

    @action
    showIndicator = (message) => {//启用加载效果
        this.indicatorVisible = true;
        if (message) {
            this.indicatorMessage = message;
        }
    }

    @action
    hiddenIndicator() {//关闭加载效果
        this.indicatorVisible = false;
    }

    @action
    setParams = (params) => {//设置查询条件
        this.params = params;
    }

    @action
    setSelectExpand = (index, data) => {//设置展开条目下标及展示数据,-1代表收起均不展开
        this.selectExpand = index;
        let option = {};
        if (data && data.charts && data.charts.length > 0) {
            let xAxisData = [], seriesData = [];
            for (let i = 0; i < data.charts.length; i++) {
                xAxisData.push(data.charts[i].OP_TIME);
                seriesData.push(data.charts[i].MONTHLY_INCOME);
            }
            option = {
                grid: {top: 20, bottom: 20, right: 20,left:10},
                tooltip: {
                    show: true,
                    trigger: 'axis',
                    formatter: '{c}',
                    backgroundColor: 'rgba(0,0,0,0)',
                    textStyle: {color: Style.color.blue},
                    position: function (point, params, dom, rect, size) {
                        return [point[0], 5];
                    },
                    axisPointer: {type: 'line', lineStyle: {color: Style.color.lightGray}}
                },
                xAxis: {
                    type: 'category',
                    axisLabel: {textStyle: {color: Style.color.gray}},
                    axisLine: {show: false},
                    axisTick: {show: false},
                    splitLine: {show: false},
                    data: xAxisData
                },
                yAxis: {
                    type: 'value',
                    axisLabel: {textStyle: {color: Style.color.gray}},
                    axisLine: {show: false},
                    axisTick: {show: false},
                    splitLine: {show: false}
                },
                series: [{
                    type: 'line',
                    smooth: true,
                    data: seriesData
                }],
                color: [Style.color.blue]
            };
        }
        this.expandData = {lineOption: option, info: data.info ? data.info : {}};//避免空指针引用异常
    }
}